package com.winsomely.leecode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 相对名次
 * 
 * @author liujiawei
 *
 */
public class FindRelativeRanks {

	public String[] findRelativeRanks(int[] score) {
		Map<Integer, Integer> map = new HashMap<>();
		String[] s = new String[score.length];
		int[] tempScore = Arrays.copyOf(score, score.length);
		Arrays.sort(tempScore);

		int L = tempScore.length;
		for (int i = 0; i < L; i++) {
			map.put(tempScore[i], L - i);
		}
		for (int i = 0; i < score.length; i++) {
			Integer index = map.get(score[i]);
			switch (index) {
			case 1:
				s[i] = "Gold Medal";
				break;
			case 2:
				s[i] = "Silver Medal";
				break;
			case 3:
				s[i] = "Bronze Medal";
				break;
			default:
				s[i] = String.valueOf(index);
				break;
			}
		}
		return s;
	}

	// 12345
	public static void main(String[] args) {
		FindRelativeRanks t = new FindRelativeRanks();
		int[] ii = { 5, 20, 3, 2, 4, 7, 1, 9, 6 };
		String[] s = t.findRelativeRanks(ii);
		for (String i : s) {
			System.out.println(i);
		}
	}

}
